package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;


    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理等级名称", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "integer", paramType = "query", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "integer", paramType = "query", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "integer", paramType = "query", required = false)
    })
    public ResponseResult<PageResponse<NursingLevelVo>> selectByPage(String name, Integer pageNum, Integer pageSize, Integer status){
       PageResponse<NursingLevelVo> pageResponse =  nursingLevelService.selectByPage(name,pageNum,pageSize,status);
       return success(pageResponse);
    }


    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> selectAll(){
        List<NursingLevelVo> list = nursingLevelService.selectAll();
        return success(list);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> selectById(@PathVariable Integer id){
        NursingLevelVo nursingLevelVo = nursingLevelService.selectById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable Integer id){
        nursingLevelService.deleteNursingLevel(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理等级")
    public ResponseResult isForbidden(@PathVariable Integer id,@PathVariable Integer status){
        nursingLevelService.isForbidden(id,status);
        return success();
    }

}
